//
//  WPTextView.m
//  01 微博
//
//  Created by zhoup on 16/5/23.
//  Copyright © 2016年 zhoup. All rights reserved.
//

#import "WPTextView.h"

@interface WPTextView()

@property(nonatomic,strong) UILabel *placeHolderLabel;

@end

@implementation WPTextView

-(void)layoutSubviews
{
    
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UILabel *label = [[UILabel alloc]init];
        label.numberOfLines = 0;
        label.x = 5;
        label.y = 7;
        self.font = [UIFont systemFontOfSize:15];
        label.font = self.font;
        label.text = @"说点什么吧";
        [label sizeToFit];
        self.placeHolderLabel = label;
        [self addSubview:label];
        
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textchange) name:UITextViewTextDidChangeNotification object:nil];
        
    }
    return self;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)textchange
{
    self.placeHolderLabel.hidden = (self.text.length > 0);
}

- (void)setPlaceholder:(NSString *)placeholder
{
    _placeholder = [placeholder copy];
    
    self.placeHolderLabel.text = _placeholder;
    [self.placeHolderLabel sizeToFit];
}

-(void)setFont:(UIFont *)font
{
    [super setFont:font];
    self.placeHolderLabel.font = font;
    [self.placeHolderLabel sizeToFit];
    
}

@end
